package com.hronline;

import org.json.JSONException;
import org.json.JSONObject;

import com.models.Status;
import com.models.User;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.DialogInterface.OnClickListener;

public class Constant {
	
	/* App Config */
	public static final String SECRET_KEY		=	"NASHSECRET123456";
	public static final String APP_CODE			=	"NASHCODE";
	public static final String SERVER_ADDRESS	=	"https://betaapiv2.peninsula-online.com/";//"https://mobileapiv2.peninsula-online.com/";
	
	
	public static final int IVALID_AUTHORIZED_TOKEN	=	2014;
	public static final int SUCCESS_CODE			=	1000;
	
	/* Save value variable using for app */
	public static User currentUser;
	public static String AUTHORIZED_TOKEN;
	
	public static final	String MY_PREFERENCES	=	"MY_PREFERENCES";
	public static final String IS_ALREADY_LOGIN	=	"IS_ALREADY_LOGIN";
	public static final String USER_INFO		=	"USER_INFO";
	public static final String MY_PIN_CODE		=	"MY_PIN_CODE";
	public static final String MANAGER_POSTION	=	"Manager";
	
	/*Common message*/
	public static final String LOADING_STRING			=	"Loading...Please wait";	
	public static final String EMAIL_PASSWORD_INVALID 	=	"Invalid username or password.\nPlease check it again";
	public static final String PREVENT_ADMIN			=	"User does not have an employee record";
	public static final String CANNOT_CONNECT_SERVER	=	"Cannot connect to server at this moment.\nPlease try again later";
	public static final String PIN_CODE_NOT_MATCH		=	"Please re-enter your pin,\nto access hronline";
	public static final String FAIL_ATTEMPT				=	"Failed Pin Attempt";
	public static final String REQUIRE_PIN_CODE			=	"Please enter your pin,\nto access hronline";
	
	/* NOTIFICATION */
	public static final String MUST_UPDATE_DASHBOARD	=	"MUST_UPDATE_DASHBOARD";
	
	public static void resetAllUserDataCaching(Context context, int mode){
		/* reset all user info in app */
		SharedPreferences preferences	=	context.getSharedPreferences(Constant.MY_PREFERENCES, mode);
		SharedPreferences.Editor editor	=	preferences.edit();
		editor.putBoolean(Constant.IS_ALREADY_LOGIN, false);
		editor.putString(Constant.MY_PIN_CODE, null);
		editor.putString(Constant.USER_INFO, null);
		editor.commit();
		
		Constant.currentUser	=	null;
	}
	
	
	public static Status parseStatusModel(JSONObject statusObject){
		
		try {
			
			Status item	=	new Status();
			item.setInternalMessage(statusObject.getString("InternalMessage"));
			item.setStatusCode(statusObject.getInt("StatusCode"));
			item .setStatusText(statusObject.getString("StatusText"));
			return item;
			
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return null;
	}
	
	
	public static final void showErrorMessage(Context context, String errorMessage)
	{
		AlertDialog.Builder builder	=	new AlertDialog.Builder(context);
		builder.setMessage(errorMessage);
		builder.setPositiveButton("OK", new OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				// TODO Auto-generated method stub
				
			}
		});
		builder.setCancelable(true);
		builder.create();
		builder.show();
	}
}
